/*
 * 鸡蛋美术商城 发现javaScript脚本文件
 * $Author: Jo
 * $Id: freeplan.js 2015-8-19 10:15:00
 * 发现脚本 Begin
*/

//点击清空搜索内容
$('.empty-search').click(function(){
    $('.search .left input').val('');
});

//监听搜索内容显示隐藏清空按钮
function isInput(){
    var val = $('.search .left input').val().length;
    if(val > 0){
        $('.empty-search').show();
    }else{
        $('.empty-search').hide(); 
    }
}

//实时监听是否输入搜索内容
$('.search .left input').bind('input propertychange', function() {  
    $('.empty-search').show();
});



//监听评论是否输入
$("#comment-text").on('input',function(e){
    isComtent();
});
function isComtent(){
	var val = $('#comment-text').val().length;
    if(val > 0){
        $('#tvd-comt .inp-com span').css("color" , "#a40101");
    }else{
        $('#tvd-comt .inp-com span').css("color" , "#a0a0a0");
    }
}


/* 评论 */
function setComment(id, comment, at_user){
    if (!id) {
        return false;
    }
    if (!comment) {
        point('请输入评论内容！', 1000);
        return false;
    }
    $.get('tvd.php?act=comment&id='+id,{comment:comment,at_user:at_user},function(result){
        if (result.error == 0) {
            /* 显示HTML */
            point('评论成功', 1000);
            atUser('');
            $('.comment-list').prepend(result.content);
        } else {
            point(result.message, 1000);
            window.location.href = 'user.php';
        }
    },'json');
    return false;
}

/* 获取评论列表 */
function getComment(){
    $.get('tvd.php?act=commentList&isAjax=1&id='+tvdId,function(result){
        if (result.error == 0) {
            if (result.content) {
                $('#tvd-comt .comment-list').append(result.content);
            }
        }
        $('#tvd-info').hide();
        $('#tvd-comt').show();
    },'json');
}
/* 评论时输入框上移 */
function comt_focus(){
    var t = $(document).scrollTop();
    $('#tvd-comt .inp-com').addClass('focus');
    $('body').bind('touchmove',function(){event.preventDefault();});
    $('#tvd-comt .comt-list').height($(window).height());
    $('#tvd-comt .comt-list').scrollTop(t);
    $('#mask').show();
}
function comt_blur(){
    var t = $('#tvd-comt .comt-list').scrollTop();
    $('#tvd-comt .inp-com').removeClass('focus');
    $('body').unbind('touchmove');
    $('#tvd-comt .comt-list').height('100%');
    $(document).scrollTop(t);
    $('#mask').hide();
    var val = $('#comment-text').val().length;
    if(val > 0){
        $('#tvd-comt .inp-com span').css("color" , "#a40101");
    }else{
        $('#tvd-comt .inp-com span').css("color" , "#a0a0a0");
        atUser('');
    }
}


/* 设置回复 */
function atUser(user) {
    if (user) {
        $('#at-user').val(user);
        $('#comment-text').attr('placeholder', '回复 '+user).focus();
    } else {
        $('#at-user').val('');
        $('#comment-text').text('');
        $('#comment-text').attr('placeholder', '我也评论一句');
    }
}

//点赞
function collect(id){
    if ($('.uncollect').length > 0) {
        $.get('tvd.php?act=collect&id='+id,function(result){
            $('.uncollect').addClass('collect').removeClass('uncollect');
        var clickNum = $('.praise3 .click-num').text();
        $('.praise3 .click-num').text(++clickNum);
        },'json');
    }
}

//百度分享
window._bd_share_config = {
    common : {
        bdText : bdText,
        bdDesc : bdDesc,
        bdUrl : bdUrl,
        bdPic : bdPic
    },
    share : [{
        "bdSize" : 16
    }],
}
with(document)[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];

//弹出分享弹窗
$('.flow-share').click(function(){
    $('#share-mask,#share-con').show();
});

//关闭分享弹窗
$('.close-share,#share-mask').click(function(){
    $('#share-mask,#share-con').hide();
});
/* 脚本 End */